package com.example.teacher.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.teacher.R
import com.example.teacher.data.Course

/**
 *@Created by 覃德玮 on 2021/9/16 11:05
 *@Email: chadewik@foxmail.com
 *@Description:
 */
class CourseListAdapter(listData: List<Course>) : RecyclerView.Adapter<CourseViewHolder>() {
    val data: List<Course>

    init {
        data = listData
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CourseViewHolder {
        val holder = CourseViewHolder(
            LayoutInflater.from(parent.context).inflate(R.layout.course_list_item, parent, false)
        )
        return holder
    }


    override fun getItemCount(): Int {
        return data.size
    }


    override fun onBindViewHolder(holder: CourseViewHolder, position: Int) {
        holder.name.text=data[position].courseName
        holder.id.text=data[position].courseId
        holder.teacher.text=data[position].teacher
        holder.hours.text=data[position].classHours.toString()
        holder.stunum.text=data[position].courseNum.toString()
    }


}

class CourseViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    val name: TextView = itemView.findViewById(R.id.coursename)
    val id:TextView=itemView.findViewById(R.id.courseid)
    val teacher: TextView = itemView.findViewById(R.id.time)
    val hours: TextView = itemView.findViewById(R.id.hours)
    val stunum: TextView = itemView.findViewById(R.id.stunum)
}